#include<stdlib.h>
#include<stdio.h>

#include"tree.h"

static int cmp_char(const void *data, const void *key);
static void pri_char(const void *data);

int main(int argc, char *argv[]){
	if(argc < 3)
		return -1;
	
	head *mytree = NULL;
	int i = 0;

	root_init(&mytree, sizeof(char));
	
	printf("开始插入\n");
	while(argv[1][i]){
		tree_insert(mytree, argv[1] + i, cmp_char);
		i++;
	}
	printf("中序遍历\n");
	tree_travel(mytree, pri_char);
	printf("\n");

	printf("小飞机来喽！\n");
	tree_delete(mytree, argv[2], cmp_char);
	tree_travel(mytree, pri_char);
	printf("\n");

	printf("AVL\n");
	tree_balance(mytree);
	tree_travel(mytree, pri_char);
	printf("\n");



	tree_destroy(&mytree);
	return 0;
}

static int cmp_char(const void *data, const void *key){
	const char * d = (const char *)data;
	const char * k = (const char *)key;
	return 	*d - *k;
}

static void pri_char(const void *data){
	const char *d = (const char *)data;
	printf("%c", *d);
}
